﻿using System;
using System.Collections;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Components;

namespace UDS.SubModule.Schedule
{
    /// <summary>
    /// Manage 的摘要说明。
    /// </summary>
    public partial class ManagePage : Page
    {
        private const int startTimeNo = 8;
        public string ClassID;
        protected string CurrDate, CurrTime;
        public static string UnameStr;
        protected string Username;

        protected override void OnInit(EventArgs e)
        {
            Username = SiteContext.Current.UserName;

            btnSubmit.Click += btnSubmit_Click;
            btnCheck.Click += btnCheck_Click;
            rbAttribute.SelectedIndexChanged += rbAttribute_SelectedIndexChanged;
            cbIsAllDay.CheckedChanged += cbIsAllDay_CheckedChanged;
            cbNeedCo.CheckedChanged += cbNeedCo_CheckedChanged;
            btnAddUser.Click += btnAddUser_Click;
            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            ClassID = (Request.QueryString["ClassID"] != null) ? Request.QueryString["ClassID"] : "0";
            CurrDate = (Request.QueryString["CurrDate"] != null) ? Request.QueryString["CurrDate"] : DateTime.Now.ToShortDateString();
            CurrTime = (Request.QueryString["CurrTime"] != null) ? Request.QueryString["CurrTime"] : "10";

            if (!Page.IsPostBack)
            {
                PopulateListView();
                UnameStr = Username;
                DayTaskFrm.Attributes["src"] = "ViewDayTask.aspx?Date=" + CurrDate + "&UnameStr=" + UnameStr;
            }
            else
            {
                lblMsg.Text = "";
                DayTaskFrm.Attributes["src"] = "ViewDayTask.aspx?Date=" + txtBeginDate.Text + "&UnameStr=" + UnameStr;
            }

            Validate();
            base.OnLoad(e);
        }

        private TaskClass ProcessFormPost()
        {
            var tc = new TaskClass();
            tc.ArrangedBy = Username;
            tc.Detail = txtDetail.Text;
            tc.Type = Int32.Parse(rbType.SelectedItem.Value);
            tc.Attribute = Int32.Parse(rbAttribute.SelectedItem.Value);
            tc.Subject = txtSubject.Text;
            tc.ProjectID = Request.Form["hdnProjectID"] != "" ? Int32.Parse(Request.Form["hdnProjectID"]) : 0;
            tc.StartTime = txtBeginDate.Text + " " + ((cbIsAllDay.Checked) ? "" : listBeginTime.SelectedItem.Text);
            tc.EndTime = txtEndDate.Text + " " + ((cbIsAllDay.Checked) ? "" : listEndTime.SelectedItem.Text);
            tc.AwakeTime = DateTime.Parse(tc.EndTime).AddMinutes(-10).ToString();
            tc.Tag = 0;
            tc.ContractList = "";
            tc.CooperatorList = UnameStr;
            //			foreach(ListItem i in this.listCooperator .Items)
            //				if(i.Selected == true)
            //					tc.CooperatorList+= i.Value.ToString()+",";

            return tc;
        }

        private void cbNeedCo_CheckedChanged(object sender, EventArgs e)
        {
            listCooperator.Visible = !listCooperator.Visible;
            btnAddUser.Visible = listCooperator.Visible;
            cbRemind.Visible = listCooperator.Visible;
            ValidateForm();
        }

        private void cbIsAllDay_CheckedChanged(object sender, EventArgs e)
        {
            listBeginTime.Visible = !listBeginTime.Visible;
            listEndTime.Visible = !listEndTime.Visible;
            cbIsRepeat.Visible = !cbIsRepeat.Visible;
        }


        private ArrayList CheckExist()
        {
            var cooperatorList = new ArrayList();
            var ExistList = new ArrayList();
            var task = new Task();

            if (cbNeedCo.Checked)
            {
                if (cbNeedCo.Checked)
                {
                    string[] UnameArr = Regex.Split(UnameStr, ",");
                    for (int uc = 0; uc < UnameArr.Length; uc++)
                    {
                        cooperatorList.Add(UnameArr[uc]);
                    }
                }
                else
                {
                    cooperatorList.Add(Username);
                }
            }
            else
            {
                cooperatorList.Add(Username);
            }

            foreach (string s in cooperatorList)
            {
                // 一天任务

                #region 如果是单天的任务

                if (txtBeginDate.Text == txtEndDate.Text)
                {
                    // 全天任务
                    if (cbIsAllDay.Checked)
                    {
                        SqlDataReader dataReader = task.GetPeriodInfo();
                        while (dataReader.Read())
                        {
                            if (task.CheckExist(Int32.Parse(dataReader[0].ToString()), s, txtBeginDate.Text))
                            {
                                var conrec = new TaskConflictRecord();
                                conrec.Username = s;
                                conrec.Date = txtBeginDate.Text;
                                conrec.Period = dataReader[0].ToString();
                                ExistList.Add(conrec);
                            }
                        }
                        dataReader.Close();
                    }
                    else
                    {
                        for (int t = Int32.Parse(listBeginTime.SelectedItem.Value); t < Int32.Parse(listEndTime.SelectedItem.Value); t++)
                        {
                            if (task.CheckExist(t, s, txtBeginDate.Text))
                            {
                                var conrec = new TaskConflictRecord();
                                conrec.Username = s;
                                conrec.Date = txtBeginDate.Text;
                                conrec.Period = t.ToString();
                                ExistList.Add(conrec);
                            }
                        }
                    }
                }

                #endregion

                // 如果是多天的任务

                #region 如果是多天的任务

                if (DateTime.Parse(txtBeginDate.Text) < DateTime.Parse(txtEndDate.Text))
                {
                    TimeSpan ts = DateTime.Parse(txtEndDate.Text) - DateTime.Parse(txtBeginDate.Text);
                    for (int t = 0; t < Int32.Parse(ts.Days.ToString()) + 1; t++) //根据天数循环添加
                    {
                        string tmpDate = DateTime.Parse(txtBeginDate.Text).AddDays(t).ToString("yyyy-MM-dd");

                        #region 如果是全天任务

                        if (cbIsAllDay.Checked) //如果是全天任务
                        {
                            SqlDataReader dataReader = task.GetPeriodInfo();
                            while (dataReader.Read())
                            {
                                if (task.CheckExist(Int32.Parse(dataReader[0].ToString()), s, tmpDate))
                                {
                                    var conrec = new TaskConflictRecord();
                                    conrec.Username = s;
                                    conrec.Date = tmpDate;
                                    conrec.Period = dataReader[0].ToString();
                                    ExistList.Add(conrec);
                                }
                            }
                            dataReader.Close();
                        }
                        #endregion

                        #region  如果是时段任务

                        else //如果是时段任务
                        {
                            if (cbIsRepeat.Checked) // 如果是时段重复
                            {
                                for (int j = Int32.Parse(listBeginTime.SelectedItem.Value); j < Int32.Parse(listEndTime.SelectedItem.Value); j++)
                                {
                                    if (task.CheckExist(j, s, tmpDate))
                                    {
                                        var conrec = new TaskConflictRecord();
                                        conrec.Username = s;
                                        conrec.Date = tmpDate;
                                        conrec.Period = j.ToString();
                                        ExistList.Add(conrec);
                                    }
                                }
                            }
                            else // 如果是全部时段
                            {
                                if (tmpDate == txtBeginDate.Text) // 如果是开始天
                                {
                                    for (int k = Int32.Parse(listBeginTime.SelectedItem.Value); k < 20; k++)
                                    {
                                        if (task.CheckExist(k, s, tmpDate))
                                        {
                                            var conrec = new TaskConflictRecord();
                                            conrec.Username = s;
                                            conrec.Date = tmpDate;
                                            conrec.Period = (k).ToString();
                                            ExistList.Add(conrec);
                                        }
                                    }
                                }
                                else if (tmpDate == txtEndDate.Text)
                                {
                                    for (int k = 1; k < Int32.Parse(listEndTime.SelectedItem.Value); k++)
                                    {
                                        if (task.CheckExist(k, s, tmpDate))
                                        {
                                            var conrec = new TaskConflictRecord();
                                            conrec.Username = s;
                                            conrec.Date = tmpDate;
                                            conrec.Period = k.ToString();
                                            ExistList.Add(conrec);
                                        }
                                    }
                                }
                                else
                                {
                                    SqlDataReader dataReader = task.GetPeriodInfo();
                                    while (dataReader.Read())
                                    {
                                        if (task.CheckExist(Int32.Parse(dataReader[0].ToString()), s, tmpDate))
                                        {
                                            var conrec = new TaskConflictRecord();
                                            conrec.Username = s;
                                            conrec.Date = tmpDate;
                                            conrec.Period = dataReader[0].ToString();
                                            ExistList.Add(conrec);
                                        }
                                    }
                                    dataReader.Close();
                                }
                            }
                        }

                        #endregion
                    }
                }

                #endregion
            }

            return ExistList;
        }

        private bool ValidateForm()
        {
            if (UnameStr == "")
            {
                lblMsg.Text = "请至少选择一个执行人";
                return false;
            }

            if (txtSubject.Text == "")
            {
                lblMsg.Text = "主题不能为空";
                return false;
            }


            if (DateTime.Parse(txtBeginDate.Text) > DateTime.Parse(txtEndDate.Text))
            {
                lblMsg.Text = "开始日期不能大于结束日期";
                return false;
            }

            if (!cbIsAllDay.Checked)
            {
                if (txtBeginDate.Text == txtEndDate.Text && listBeginTime.SelectedItem.Value == listEndTime.SelectedItem.Value)
                {
                    lblMsg.Text = "开始时间段和结束时间段不能相同";
                    return false;
                }

                if (txtBeginDate.Text == txtEndDate.Text && Int32.Parse(listBeginTime.SelectedItem.Value) >= Int32.Parse(listEndTime.SelectedItem.Value))
                {
                    lblMsg.Text = "开始时间段不能大于等于结束时段";
                    return false;
                }
            }
            if (cbNeedCo.Checked)
            {
                bool flag = true;
                foreach (ListItem i in listCooperator.Items)
                {
                    if (i.Selected)
                    {
                        flag = false;
                    }
                }

                if (flag)
                {
                    lblMsg.Text = "请选择协同人";
                    return false;
                }
                return true;
            }

            return true;
        }

        public string GetClassName()
        {
            if (ClassID == "0")
            {
                return "请选择项目";
            }
            return ProjectClass.GetProjectName(Int32.Parse(ClassID));
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string info = "<link href=\"../../Css/BasicLayout.css\" rel=\"stylesheet\" type=\"text/css\">";
            info += "<body leftmargin=\"0\" topmargin=\"0\">";
            if (ValidateForm())
            {
                if (rbAttribute.SelectedItem.Value == "1")
                {
                    ArrayList ExistList = CheckExist();
                    if (ExistList.Count > 0)
                    {
                        info += "<table width=100% height=30 border=0 cellpadding=0 cellspacing=0 class=GbText>";
                        info += "<tr>";
                        info += "<td background=\"../../Images/treetopbg.jpg\">&nbsp;&nbsp;任务时段冲突检测结果</td>";
                        info += "</tr>";
                        info += "</table>";

                        info += "<table width=100% border=1 cellpadding=0 cellspacing=0 style=BORDER-COLLAPSE: collapse borderColor=93BEE2 class=GbText>";
                        info += " <tr align=center bgcolor=#e8f4ff> ";
                        info += "<td width=30% height=24>检测人员</td>";
                        info += "<td width=30% height=24>日期</td>";
                        info += "<td height=24>时间</td>";
                        info += "</tr>";
                        foreach (TaskConflictRecord conrec in ExistList)
                        {
                            int b = Int32.Parse(conrec.Period);
                            var dt = new DateTime(1999, 1, 1, 8, 0, 0, 0);
                            var ts = new TimeSpan(0, 0, (b - 1) * 30, 0, 0);
                            DateTime bt = dt.Add(ts);
                            DateTime et = bt.Add(new TimeSpan(0, 0, 30, 0, 0));

                            info += "<tr align=center><td height=20>" + conrec.Username + "</td>";
                            info += "<td>" + conrec.Date + "</td>";
                            info += "<td>" + bt.ToShortTimeString() + "---" + et.ToShortTimeString() + "</td>";
                            info += "</tr>";
                        }
                        info += "</table>";
                        info += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
                        info += "<tr><td height=\"36\" align=\"center\"><font color=\"#FF0000\">以上时段有冲突</font></td></tr></table>";
                        Response.Write("<script language=javascript>var checkwin=window.open('','check','toolbar=no,scrollbars=yes,width=280,height=200,resizable=yes');");
                        Response.Write("checkwin.document.write('" + info + "');checkwin.moveTo(0,0);checkwin.focus();</script>");
                        return;
                    }
                }

                var cooperatorList = new ArrayList();
                var task = new Task();
                string TaskID = task.AddTask(ProcessFormPost());

                //处理短信提醒
                if (cbRemind.Checked)
                {
                    SMS.SendMsg(Username, UnameStr, "您从 " + Components.Staff.GetRealNameByUsername(Username) + " 处接收到了一份新的任务", SMSType.SiteMessage, DateTime.Now, "", 0, 0);
                }

                if (rbAttribute.SelectedItem.Value == "1")
                {
                    if (cbNeedCo.Checked)
                    {
                        string[] UnameArr = Regex.Split(UnameStr, ",");
                        for (int uc = 0; uc < UnameArr.Length; uc++)
                        {
                            cooperatorList.Add(UnameArr[uc]);
                        }
                    }
                    else
                    {
                        cooperatorList.Add(Username);
                    }

                    foreach (string s in cooperatorList)
                    {
                        // 一天任务

                        #region 如果是单天的任务

                        if (txtBeginDate.Text == txtEndDate.Text)
                        {
                            // 全天任务
                            if (cbIsAllDay.Checked)
                            {
                                SqlDataReader dataReader = task.GetPeriodInfo();
                                while (dataReader.Read())
                                {
                                    task.AddTaskToSchedule(Int32.Parse(TaskID), Int32.Parse(dataReader[0].ToString()), s, txtBeginDate.Text, s.ToLower() == Username.ToLower() ? true : false);
                                }
                            }
                            else
                            {
                                for (int t = Int32.Parse(listBeginTime.SelectedItem.Value); t < Int32.Parse(listEndTime.SelectedItem.Value); t++)
                                {
                                    task.AddTaskToSchedule(Int32.Parse(TaskID), t, s, txtBeginDate.Text, s.ToLower() == Username.ToLower() ? true : false);
                                }
                            }
                        }

                        #endregion

                        // 如果是多天的任务

                        #region 如果是多天的任务

                        if (DateTime.Parse(txtBeginDate.Text) < DateTime.Parse(txtEndDate.Text))
                        {
                            TimeSpan ts = DateTime.Parse(txtEndDate.Text) - DateTime.Parse(txtBeginDate.Text);
                            for (int t = 0; t < Int32.Parse(ts.Days.ToString()) + 1; t++) //根据天数循环添加
                            {
                                string tmpDate = DateTime.Parse(txtBeginDate.Text).AddDays(t).ToString("yyyy-MM-dd");

                                #region 如果是全天任务

                                if (cbIsAllDay.Checked) //如果是全天任务
                                {
                                    SqlDataReader dataReader = task.GetPeriodInfo();
                                    while (dataReader.Read())
                                    {
                                        task.AddTaskToSchedule(Int32.Parse(TaskID), Int32.Parse(dataReader[0].ToString()), s, tmpDate, s.ToLower() == Username.ToLower() ? true : false);
                                    }
                                }
                                #endregion

                                #region  如果是时段任务

                                else //如果是时段任务
                                {
                                    if (cbIsRepeat.Checked) // 如果是时段重复
                                    {
                                        for (int j = Int32.Parse(listBeginTime.SelectedItem.Value); j < Int32.Parse(listEndTime.SelectedItem.Value); j++)
                                        {
                                            task.AddTaskToSchedule(Int32.Parse(TaskID), j, s, tmpDate, s.ToLower() == Username.ToLower() ? true : false);
                                        }
                                    }
                                    else // 如果是全部时段
                                    {
                                        if (tmpDate == txtBeginDate.Text) // 如果是开始天
                                        {
                                            for (int k = Int32.Parse(listBeginTime.SelectedItem.Value); k <= 20; k++)
                                            {
                                                task.AddTaskToSchedule(Int32.Parse(TaskID), k, s, tmpDate, s.ToLower() == Username.ToLower() ? true : false);
                                            }
                                        }
                                        else if (tmpDate == txtEndDate.Text)
                                        {
                                            for (int k = 1; k < Int32.Parse(listEndTime.SelectedItem.Value); k++)
                                            {
                                                task.AddTaskToSchedule(Int32.Parse(TaskID), k, s, tmpDate, s.ToLower() == Username.ToLower() ? true : false);
                                            }
                                        }
                                        else
                                        {
                                            SqlDataReader dataReader = task.GetPeriodInfo();
                                            while (dataReader.Read())
                                            {
                                                task.AddTaskToSchedule(Int32.Parse(TaskID), Int32.Parse(dataReader[0].ToString()), s, tmpDate, s.ToLower() == Username.ToLower() ? true : false);
                                            }
                                        }
                                    }
                                }

                                #endregion
                            }
                        }

                        #endregion
                    }
                }

                else if (rbAttribute.SelectedItem.Value == "0")
                {
                    if (cbNeedCo.Checked)
                    {
                        string[] UnameArr = Regex.Split(UnameStr, ",");
                        for (int uc = 0; uc < UnameArr.Length; uc++)
                        {
                            cooperatorList.Add(UnameArr[uc]);
                        }
                    }
                    else
                    {
                        cooperatorList.Add(Username);
                    }
                    foreach (string s in cooperatorList)
                    {
                        task.AddTaskToSchedule(Int32.Parse(TaskID), 0, s, txtEndDate.Text, s.ToLower() == Username.ToLower() ? true : false);
                    }
                }

                Response.Write("<script language=javascript>alert('添加成功!');window.opener.location='TaskList.aspx?displayType=1';window.close();</script>");
            }
        }


        private void btnCheck_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                string info = "<link href=\"../../Css/BasicLayout.css\" rel=\"stylesheet\" type=\"text/css\">";
                info += "<body leftmargin=\"0\" topmargin=\"0\">";
                //Response.Write("验证成功!");
                ArrayList ExistList = CheckExist();
                if (ExistList.Count > 0)
                {
                    info += "<table width=100% height=30 border=0 cellpadding=0 cellspacing=0 class=GbText>";
                    info += "<tr>";
                    info += "<td background=\"../../Images/treetopbg.jpg\">&nbsp;&nbsp;任务时段冲突检测结果</td>";
                    info += "</tr>";
                    info += "</table>";

                    info += "<table width=100% border=1 cellpadding=0 cellspacing=0 style=BORDER-COLLAPSE: collapse borderColor=93BEE2 class=GbText>";
                    info += " <tr align=center bgcolor=#e8f4ff> ";
                    info += "<td width=30% height=24>检测人员</td>";
                    info += "<td width=30% height=24>日期</td>";
                    info += "<td height=24>时间</td>";
                    info += "</tr>";
                    foreach (TaskConflictRecord conrec in ExistList)
                    {
                        int b = Int32.Parse(conrec.Period);
                        var dt = new DateTime(1999, 1, 1, 8, 0, 0, 0);
                        var ts = new TimeSpan(0, 0, (b - 1) * 30, 0, 0);
                        DateTime bt = dt.Add(ts);
                        DateTime et = bt.Add(new TimeSpan(0, 0, 30, 0, 0));

                        info += "<tr align=center><td height=20>" + conrec.Username + "</td>";
                        info += "<td>" + conrec.Date + "</td>";
                        info += "<td>" + bt.ToShortTimeString() + "---" + et.ToShortTimeString() + "</td>";
                        info += "</tr>";
                    }
                    info += "</table>";
                    info += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
                    info += "<tr><td height=\"36\" align=\"center\"><font color=\"#FF0000\">以上时段有冲突</font></td></tr></table>";
                    Response.Write("<script language=javascript>var checkwin=window.open('','check','toolbar=no,scrollbars=yes,width=280,height=200,resizable=yes');");
                    Response.Write("checkwin.document.write('" + info + "');checkwin.moveTo(0,0);checkwin.focus();</script>");
                }
                else
                {
                    info += "<table width=\"100%\" height=\"30\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"GbText\">";
                    info += "<tr><td background=\"treetopbg.jpg\">&nbsp;&nbsp;任务时段冲突检测结果</td>";
                    info += "</tr>";
                    info += "</table>";
                    info += "<table width=\"100%\" height=\"160\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" borderColor=\"93BEE2\" class=\"GbText\" style=\"BORDER-COLLAPSE: collapse\">";
                    info += "<tr align=\"center\"> ";
                    info += "<td height=\"20\"><font color=\"#FF0000\">您检测的时段没有冲突<br>";
                    info += "<br>  可以安排任务 </font></td></tr></table>";
                    Response.Write("<script language=javascript>var checkwin=window.open('冲突检测结果','check','toolbar=no,scrollbars=yes,width=200,height=200,resizable=yes');");
                    Response.Write("checkwin.document.write('" + info + "');checkwin.moveTo(0,0);checkwin.focus();</script>");
                }
            }
        }

        private void rbAttribute_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rbAttribute.SelectedItem.Value == "1")
            {
                btnCheck.Enabled = true;
                cbIsAllDay.Enabled = true;
                cbIsRepeat.Enabled = true;
                listBeginTime.Enabled = true;
                txtBeginDate.Enabled = true;
            }
            else
            {
                listBeginTime.Enabled = false;
                txtBeginDate.Enabled = false;
                cbIsAllDay.Enabled = false;
                cbIsRepeat.Enabled = false;
                btnCheck.Enabled = false;
            }
        }

        private void btnAddUser_Click(object sender, EventArgs e)
        {
            for (int i = listCooperator.Items.Count - 1; i >= 0; i--)
            {
                if (listCooperator.Items[i].Selected)
                {
                    var re = new Regex("," + listCooperator.Items[i].Value, RegexOptions.IgnoreCase);
                    Match m = re.Match("," + UnameStr);
                    if (m.Success)
                    {
                        lblMsg.Text = "已经添加此成员!";
                        return;
                    }
                    UnameStr += "," + listCooperator.Items[i].Value;
                }
            }
            if (UnameStr.Substring(0, 1) == ",")
            {
                UnameStr = UnameStr.Substring(1, UnameStr.Length - 1);
            }
            DayTaskFrm.Attributes["src"] = "ViewDayTask.aspx?UnameStr=" + UnameStr;
        }

        #region 初始化下拉列表框

        /// <summary>
        /// 对下拉列表进行初始化
        /// </summary>
        private void PopulateListView()
        {
            #region 开始时间与结束时间初始化

            var task = new Task();
            SqlDataReader dataReader = task.GetPeriodInfo();
            while (dataReader.Read())
            {
                string[] b = dataReader[1].ToString().Split('-');
                listBeginTime.Items.Add(new ListItem(b[0], dataReader[0].ToString()));
                listEndTime.Items.Add(new ListItem(b[0], dataReader[0].ToString()));
            }
            dataReader.Close();

            listBeginTime.SelectedIndex = Int32.Parse(CurrTime) - startTimeNo;
            listEndTime.SelectedIndex = listBeginTime.SelectedIndex + 1;

            //			listBeginTime.DataTextField = "period";
            //			listBeginTime.DataValueField = "id";
            //			listBeginTime.DataSource = dataReader;
            //			listBeginTime.DataBind();
            //			for(int j=startTimeNo;j<19;j++)
            //			{
            //				ListItem li = new ListItem(j.ToString()+":00",j.ToString());
            //				listBeginTime.Items.Insert(j-8,li);
            //				listEndTime.Items.Insert(j-8,li);
            //			}

            txtBeginDate.Text = DateTime.Parse(CurrDate).ToString("yyyy-MM-dd");
            //			listBeginTime.SelectedIndex   = Int32.Parse(CurrTime)-startTimeNo;
            txtEndDate.Text = DateTime.Parse(CurrDate).ToString("yyyy-MM-dd");

            #endregion

            #region 任务属性初始化

            rbAttribute.Items.Add(new ListItem("独占任务", "1"));
            rbAttribute.Items.Add(new ListItem("限时任务", "0"));
            rbAttribute.Items[0].Selected = true;

            #endregion

            #region 任务类型初始化

            rbType.Items.Add(new ListItem("会议", "1"));
            rbType.Items.Add(new ListItem("文案", "2"));
            rbType.Items.Add(new ListItem("来访", "3"));
            rbType.Items.Add(new ListItem("电话", "4"));
            rbType.Items.Add(new ListItem("走访", "5"));
            rbType.Items.Add(new ListItem("外出", "6"));
            rbType.Items.Add(new ListItem("假期", "7"));
            rbType.Items.Add(new ListItem("出差", "8"));
            rbType.Items[0].Selected = true;

            #endregion

            #region 协同人员列表初始化

            listCooperator.DataTextField = "RealName";
            listCooperator.DataValueField = "Name";
            listCooperator.DataSource = Staff.GetAllStaff(false);
            listCooperator.DataBind();

            #endregion

            lblArrangedBy.Text = Components.Staff.GetRealNameByUsername(Username);
        }

        #endregion
    }
}